import matplotlib.pyplot as plt
import pandas as pd
from datetime import datetime

plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']  # 指定默认字体：解决plot不能显示中文问题
plt.rcParams['axes.unicode_minus'] = False

data = pd.read_csv("./data/content.csv")
time = data['发送时间']
time = time.apply(lambda x: datetime.fromtimestamp(x).strftime("%Y-%m-%d"))
time = time.value_counts().sort_index()
x = time.index.to_list()

# 设置图框的大小
fig2 = plt.figure(figsize=(10, 6))

plt.title("《夺冠》根据日期评论数量")
plt.xlabel("日期")
plt.ylabel("评论数量")

date_x = [i for u, i in enumerate(x) if u % 10 == 0]
plt.xticks(range(0, len(x), 10), date_x)

plt.plot(x, time, linestyle='-', linewidth=1, color='green')

# 为了避免x轴日期刻度标签的重叠，设置x轴刻度自动展现，并且45度倾斜
fig2.autofmt_xdate(rotation=45)
plt.show()
